{include file="header.htm" /}
<body class="bodystyle">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-50">
    <div class="flexigrid flexigrid-xin">
        <div class="header-bar">
            <div class="more">
                <div class="search" style="background-color: #f7f7f7;">
                    <div class="content">
                        <div class="ey-form-item"><label class="users-form-item-label">批量设置：</label></div>
                        <!--<div class="ey-form-item">-->
                            <!--<div class="users-form-item-content">-->
                                <!--<div class="users-select">-->
                                    <!--<div tabindex="0" class="users-select-selection">-->
                                        <!--<label><input type="checkbox" id="set_is_join" title="参与秒杀">&nbsp;参与秒杀</label>-->
                                    <!--</div>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="ey-form-item">
                            <div class="users-form-item-content">
                                <div class="users-select">
                                    <div tabindex="0" class="users-select-selection">
                                        <div class="sDiv2">
                                            <input type="text" size="50" id="set_seckill_price" class="qsbox {eq name='$fetch' value='view'}color-no-drop no-drop{/eq}" {eq name='$fetch' value='view'}disabled{/eq} placeholder="秒杀价格" style="vertical-align:unset" onkeyup="this.value=this.value.replace(/[^\d\.]/g,'');" onpaste="this.value=this.value.replace(/[^\d\.]/g,'');">&nbsp;元&nbsp;
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="ey-form-item">
                            <div class="users-form-item-content">
                                <div class="users-select">
                                    <div tabindex="0" class="users-select-selection">
                                        <div class="sDiv2">
                                            <input type="text" size="50" id="set_seckill_stock" class="qsbox {eq name='$fetch' value='view'}color-no-drop no-drop{/eq}" {eq name='$fetch' value='view'}disabled{/eq} placeholder="秒杀库存" style="vertical-align:unset" onkeyup="this.value=this.value.replace(/[^\d\,]/g,'');" onpaste="this.value=this.value.replace(/[^\d\,]/g,'');">&nbsp;件&nbsp;
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="ey-form-item" style="margin-left: 20px;">
                            <div class="users-form-item-content">
                                <span class="bt-xin {eq name='$fetch' value='view'}no-drop btn-no-drop{/eq}" {neq name='$fetch' value='view'}onclick="batchSetUse();"{/neq}>应用</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="flexigrid">
        <div class="bDiv mt15" style="height: auto;">
            <form id="goodsSpecForm">
                <input type="hidden" id="aid" name="aid" value="{$aid}">
                <input type="hidden" id="goods_id" name="goods_id" value="{$goods_id}">
                <div id="goodsSpecCombi">{$goodsSpecCombi}</div>
            </form>
        </div>
    </div>
    <div class="bot3 {eq name='$fetch' value='view'}none{/eq}">
        <a href="javascript:void(0);" onclick="submitGoodsSpec();" class="ncap-btn-big ncap-btn-green"><span>确认</span></a>
        <a class="ncap-btn-big ncap-btn-no" href="javascript:void(0);" onclick="parent.closeSelectGoods(true);" title="关闭">关闭</a>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        // 合并商品规格单元格
        mergeGoodsSpecCells();
    });

    // 合并商品规格单元格
    function mergeGoodsSpecCells() {
        var tab = document.getElementById("goodsSpecTable");
        var maxCol = 2, val, count, start;
        if (tab != null) {
            for (var col = maxCol - 1; col >= 0; col--) {
                count = 1;
                val = "";
                for (var i = 0; i < tab.rows.length; i++) {
                    if (val == tab.rows[i].cells[col].innerHTML) {
                        count++;
                    } else {
                        if (count > 1) {
                            start = i - count;
                            tab.rows[start].cells[col].rowSpan = count;
                            for (var j = start + 1; j < i; j++) {
                                tab.rows[j].cells[col].style.display = "none";
                            }
                            count = 1;
                        }
                        val = tab.rows[i].cells[col].innerHTML;
                    }
                }
                if (count > 1) {
                    start = i - count;
                    tab.rows[start].cells[col].rowSpan = count;
                    for (var j = start + 1; j < i; j++) {
                        tab.rows[j].cells[col].style.display = "none";
                    }
                }
            }
        }
    }

    // 批量设置
    function batchSetUse() {
        var set_seckill_price = $('#set_seckill_price').val() ? $('#set_seckill_price').val() : 0;
        if (0 >= set_seckill_price) {
            layer.alert('请设置秒杀价格', {title: false, closeBtn: false}, function() {
                layer.closeAll();
                $('#set_seckill_price').focus();
            });
            return false;
        }
        var set_seckill_stock = $('#set_seckill_stock').val() ? $('#set_seckill_stock').val() : 0;
        set_seckill_stock = parseInt(set_seckill_stock);
        if (0 >= set_seckill_stock) {
            layer.alert('请设置秒杀库存', {title: false, closeBtn: false}, function() {
                layer.closeAll();
                $('#set_seckill_stock').focus();
            });
            return false;
        }
        // 批量设置价格
        $('.seckill-price').val(set_seckill_price);
        // 批量设置库存  不能大于原来库存
        $(".seckill-stock").each(function(){
            var max_stock = $(this).data('maxstock');
            if (max_stock >= set_seckill_stock ) {
                $(this).val(set_seckill_stock);
            }else{
                $(this).val(max_stock);
            }
        });
        // $('.seckill-stock').val(set_seckill_stock);

        // 批量参与积分商城
        // $('.is-join').attr('checked', false);
        // if ($('#set_is_join').is(':checked')) $('.is-join').attr('checked', true);
    }

    // 提交积分商品入库
    function submitGoodsSpec() {
        // var is_join_num = 0;
        // $(".is-join").each(function (index,value) {
        //     if ($(this).is(':checked')) {
        //         is_join_num++;
        //         var price = $(".seckill-price").eq(index).val();
        //         if (0 >= price){
        //             showErrorMsg('秒杀价格不能为0！');
        //             $(".seckill-price").eq(index).focus();
        //         }
        //     }
        // });
        // if (0 == is_join_num) {
        //     showErrorMsg('请至少选择一个规则参与秒杀！');
        //     return false;
        // }

        $(".seckill-price").each(function (index,value) {
            if (0 >=$(this).val()) {
                showErrorMsg('秒杀价格不能为0！');
                $(".seckill-price").eq(index).focus();
            }
        });
        layer_loading('正在处理');
        $.ajax({
            url : "{:weapp_url('Seckill/Seckill/multi_specification_list', ['_ajax'=>1])}",
            data: $('#goodsSpecForm').serialize(),
            type: 'post',
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    var goodsID = $('#goods_id').val();
                    if (0 === parseInt(res.data.count)) {
                        parent.$('#notSet_' + goodsID).show();
                        parent.$('#hasSet_' + goodsID).hide();
                        parent.$('#goodsSpecSet_' + goodsID).val(0);
                    } else {
                        parent.$('#notSet_' + goodsID).hide();
                        parent.$('#hasSet_' + goodsID).show();
                        parent.$('#goodsSpecSet_' + goodsID).val(1);
                    }
                    var aid = $("input[name=aid]").val();
                    if (parent.$('#set_spec_' + aid)) {
                        parent.$('#set_spec_' + aid).text('编辑秒杀价格及库存');
                        parent.$('#set_spec_' + aid).addClass('green');
                    }
                    layer.msg(res.msg, {time: 1000}, function() {
                        parent.layer.closeAll();
                    });
                } else {
                    layer.alert(res.msg, {icon: 0, title: false, closeBtn: false});
                }
            }
        });
    }


</script>
{include file="footer.htm" /}
